package com.mapbased.cc.valid;

import com.mapbased.wfw.RenderContext;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2004</p>
 *
 * <p>Company: mapbased.com</p>
 *
 * @author chy_hs(Baily)
 * @version 1.0
 */
public class Number
    implements Validator
{
    private int min=Integer.MIN_VALUE;
    private int max=Integer.MAX_VALUE;
    /**
     *
     * @param value String
     * @return boolean
     * @todo Implement this com.mapbased.cc.valid.Validator method
     */
    public boolean isValid(String value,RenderContext rc)
    {
        int i=0;
        try
        {
            i=Integer.parseInt(value);
        }
        catch(NumberFormatException ex)
        {
            return false;
        }
        return i >= min && i <= max;
    }

    public void setMin(int min)
    {
        this.min=min;
    }

    public void setMax(int max)
    {
        this.max=max;
    }

    public int getMin()
    {
        return min;
    }

    public int getMax()
    {
        return max;
    }

    public String toString()
    {
        StringBuffer sb=new StringBuffer(20);
        sb.append("值必须在 [");
        sb.append(this.min);
        sb.append(",").append(this.max).append("] 之间.");
        return sb.toString();
    }
}
